package view;

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ResourceBundle;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import control.Controller;

public class View extends JFrame {
    
    
    private ResourceBundle myResources;
    private ActionListener myOnePeriodListener;
    private ActionListener myTwoPeriodListener;
    private ActionListener myThreePeriodListener;
    private MouseListener myMouseListener;
    private Controller myController;
    private DrawBubble myDrawBubble;
    
    
    protected void makeListeners () {
        // listener for "high-level" events, i.e., those made
        // up of a sequence of low-level events, like a button
        // press (mouse down and up within a button object)
        myOnePeriodListener = new ActionListener() {
            @Override
            public void actionPerformed (ActionEvent e) {
                //echo("action", e);
                myController.print();
            }
        };
        
        myTwoPeriodListener = new ActionListener() {
            @Override
            public void actionPerformed (ActionEvent e) {
                //echo("action", e);
                myController.print();
            }
        };
        
        myThreePeriodListener = new ActionListener() {
            @Override
            public void actionPerformed (ActionEvent e) {
                //echo("action", e);
                myController.print();
            }
        };
        
        myMouseListener = new MouseListener() {
            @Override
            public void mouseClicked (MouseEvent e) {
                myController.print();
                double x=e.getX();
                double y=e.getY();
                myDrawBubble.clickBubble(x, y);
            }

            @Override
            public void mouseEntered (MouseEvent arg0) {
                // TODO Auto-generated method stub
                
            }

            @Override
            public void mouseExited (MouseEvent arg0) {
                // TODO Auto-generated method stub
                
            }

            @Override
            public void mousePressed (MouseEvent arg0) {
                // TODO Auto-generated method stub
                
            }

            @Override
            public void mouseReleased (MouseEvent arg0) {
                // TODO Auto-generated method stub
                
            }
            };
    }
    
    
    public View (String title) {
        // set properties of frame
        setTitle(title);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(700, 250);
       myController=new Controller();

        // create and arrange sub-parts of the GUI
        myResources = ResourceBundle.getBundle("resources.English" );
        makeListeners();
        getContentPane().add(makeButton(), BorderLayout.NORTH);
        myDrawBubble=DrawBubble.getDrawBubble();
        getContentPane().add(myDrawBubble, BorderLayout.CENTER);
       myDrawBubble.addMouseListener(myMouseListener); 
       // repaint();
        // size and display the GUI
       // pack();
        setVisible(true);
    }
    
    protected JComponent makeButton () {
        JPanel result = new JPanel();
     
        result.add(makeOnePeriodButton());
        result.add(makeTwoPeriodButton());
        result.add(makeThreePeriodButton());
        
        return result;
    }

    protected JComponent makeCanvas () {
        JPanel result = new JPanel();
     
        result.add(makeOnePeriodButton());
        
        
        return result;
    }
    protected JButton makeOnePeriodButton () {
        JButton result = new JButton(myResources.getString("OnePeriod"));
        result.addActionListener(myOnePeriodListener);
        
        return result;
    }
    
    protected JButton makeTwoPeriodButton () {
        JButton result = new JButton(myResources.getString("TwoPeriod"));
        result.addActionListener(myTwoPeriodListener);
        
        return result;
    }
    
    protected JButton makeThreePeriodButton () {
        JButton result = new JButton(myResources.getString("ThreePeriod"));
        result.addActionListener(myThreePeriodListener);
        
        return result;
    }
    


    public static void main (String[] args) {
        new View("wula");
    }
}
